/**
 * 负责与redux通信的容器组件
 */
import { connect } from "react-redux";

import {
    createIncrementAction,
    createDecrementAction,
    createIncrementAsyncAction,
} from "../../redux/count_action";

import CountUI from "../../components/Count";

// mapStateToProps函数的返回值会作为状态传入UI组件的props中
const mapStateToProps = (state) => ({ count: state });

// mapDispatchToProps函数的返回值作为操作状态的方法函数传入UI组件的props中
const mapDispatchToProps = (dispatch) => ({
    increment: (number) => {
        dispatch(createIncrementAction(number));
    },
    decrement: (number) => {
        dispatch(createDecrementAction(number));
    },
    incrementAsync: (number, time) => {
        dispatch(createIncrementAsyncAction(number, time));
    },
});

// 创建并暴露一个Count的容器组件
export default connect(mapStateToProps, mapDispatchToProps)(CountUI);
